﻿<html>

	<head>
		<title>订单管理</title>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">

		<link href="../../css/skin/default/style.css" rel="stylesheet" type="text/css" />
		<link href="../../css/dialog.css" rel="stylesheet">
		<link href="../../js/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />

		<script src="../../js/lib/jquery/jquery-1.10.2.min.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>

		<script src="../../js/lib/ligerUI/js/plugins/ligerPopupEdit.js"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerRadio.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTree.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTip.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerMenu.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerToolBar.js" type="text/javascript"></script>
		<script src="../../js/lib/jquery.form.js" type="text/javascript"></script>
		<script src="../../js/lib/json2.js" type="text/javascript"></script>
		<script src="../../js/dialog.js"></script>
		<script src="../../js/JS/layout.js"></script>
		<script src="../../js/constants.js" type="text/javascript"></script>
		<script src="../../js/api.js" type="text/javascript"></script>
		<script src="../../js/datetool.js" type="text/javascript"></script>
		<style>
			body {
				height: 100%;
			}
		</style>
		<script type="text/javascript">
			var manager;
			var Fstatus = $api.getparastr("status");
			$(document).hover(parent.hindMenu);

			$(function() {
				$("form").ligerForm();
				if($api.isEmpty(Fstatus)) Fstatus = 0;
				else
					$("#Fstatus").val(Fstatus);
				initContorl();
				initView();

			});

			function initView() {
				let saleUrl = BaseUrl + "storesale/sql?token=" + $api.getStorage("token");
				let url = saleUrl + "&Fstatus=" + Fstatus + "&Fkey=&Fsdt=" + $("#sdt").val() + "&Fedt=" + $("#edt").val();
				manager = $("#maingrid").ligerGrid({
						columns: [{
								display: '商品',
								width: 380,
								align: 'left',
								render: function(rowdata, rowindex, value) {
									if(rowdata.IsHead) {
										rowdata.Head.Fdate = rowdata.Head.Fdate.replace("T", " ");
										var i = rowdata.Head.Fdate.indexOf('.');
										rowdata.Head.Fdate = rowdata.Head.Fdate.substr(0, i);
										return '<span style="font-weight:bold;margin-right:5px;">' + rowdata.Head.Fdate + '</span> 订单号:' + rowdata.Head.Fcode;
									} else {
										//									var Fattr = "";
										//									var arr;
										//									if(rowdata.Detail.Fattr) {
										//										arr = JSON.parse(rowdata.Detail.Fattr);
										//									}
										//									for(var i in arr) {
										//										var row = arr[i];
										//										Fattr += row.Fattr + ":" + row.Fvalue + "；";
										//									}
										var ret = "<div style='margin:5px;height:120px;'><img src=" + rowdata.Detail.Fimg + " class='listimgs' style='float:left;top:5px' />";
										ret += "<div style='float:left; margin-left:5px'><span>【" + rowdata.Detail.Fsendnum + "】" + rowdata.Detail.Fpname + "</span><br/>";
										if(!$api.isEmpty(rowdata.Detail.Fmemo))
											ret += "<span style='color:#999'>" + rowdata.Detail.Fmemo + "</span><br/>";
										ret += "<span style='color:#999'>" + rowdata.Detail.Ft1 + "</span>"
										ret += "<div><div>"
										return ret;
									}
								}
							},
							{
								display: '销售单价',
								name: 'salePrice',
								width: 120,
								align: 'center',
								render: function(rowdata, rowindex, value) {
									return "￥" + $api.toMoney(rowdata.Detail.Fprice);
								}
							},
							{
								display: '数量',
								name: 'Num',
								width: 100,
								align: 'center',
								render: function(rowdata, rowindex, value) {
									return rowdata.Detail.Fnum + '件';
								}
							},
							{
								display: '配送状态',
								name: 'Fpsstatus',
								width: 120,
								render: function(rowdata, rowindex, value) {

									if(!rowdata.IsHead && rowdata.Head) {
										let ret = '';
										if(rowdata.Head.Fisback == 1) {
											ret = "【有退货】";
										}
										if(rowdata.Head.Fstatus == 2)
											return "待收货" + ret;
										else if(rowdata.Head.Fstatus == 3)
											return "部分待收货" + ret;
										else if(rowdata.Head.Fstatus == 4)
											return "待收货" + ret;
										else if(rowdata.Head.Fstatus == 5)
											return "已发货" + ret;
										else if(rowdata.Head.Fstatus == 6)
											return "已完成" + ret;
									}
									return "";
								}
							},
							{
								display: '商品操作',
								name: 'handler',
								width: 100,
								align: 'center',
								render: function(rowdata, rowindex, value) {
									if(!rowdata.IsHead && rowdata.Head) {
										var ret = "";
										//已付款待发货，已发部分货
										if(rowdata.Head.Fstatus == 2 || rowdata.Head.Fstatus == 3) {
											ret += "<a class='listbtn' style='width:75px;display:block;' onclick='SendDriver(" + rowindex + ");'>发货</a><br/>" +
												ret += "<a class='listbtn' style='width:75px;display:block;' onclick='Return(" + rowindex + ");'>退货</a>" +

										}
										if(rowdata.Head.Fisback == 1)
											ret += "<a class='listbtn'  style='width:75px;;margin-top:5px;color:#fff;display:block;' onclick='ReturnDetail(" + rowindex + ");'>退货详情</a>";

										ret += "<a class='listbtn' style='width:75px;;margin-top:5px;color:#fff;display:block;'  onclick='Detail(" + rowindex + ");' >订单详情</a>";

										return ret;
									}

									return "";
								}
							],
							url: url,
							dataAction: 'server',
							width: '100%',
							height: 'auto',
							isScroll: true,
							method: 'get',
							rowHeight: "auto",
							pageSize: 20,
							rowAttrRender: function(rowdata, rowid) {
								if(rowdata.IsHead) {
									return "style='background:#f3f3f3;'";
								}
							},
							usePager: true, //是否分页  
							onDblClickRow: function(data, rowindex, rowobj) {
								if(rowdata.Head)
									parent.f_addTab(-1, '订单详情', 'vstore/tb_sale_store/Detail.html?Fcode=' + data.Head.Fcode);
								else
									parent.f_addTab(-1, '订单详情', 'vstore/tb_sale_store/Detail.html?Fcode=' + data.Fcode);
							}
						});

				}

				var sdtManger, edtManager;

				function initContorl() {
					sdtManger = $("#sdt").ligerGetDateEditorManager({
						absolute: false,
						format: "yyyy-MM-dd"
					});
					edtManager = $("#edt").ligerGetDateEditorManager({
						absolute: false,
						format: "yyyy-MM-dd"
					});

					var dataUtil = new datetool();

					var dateEnd = dataUtil.getNowFormatDate(0);  
					var dateStart = dataUtil.getNowFormatDate(24 * 60 * 60 * 1000 * 30);

					  
					$("#sdt").val(dateStart);  
					$("#edt").val(dateEnd);

				}

				//发货
				function SendDriver(i) {

					var row = manager.getRow(i);

					parent.f_addTab(-1, '订单发货', 'vstore/tb_sale_store/SendMail.html?Fcode=' + row.Head.Fcode);
				}

				//退货
				function Return(i) {
					var row = manager.getRow(i);
					parent.f_addTab(-1, '订单退货', "vstore/tb_sale_store/Return.html?Fcode=" + row.Head.Fcode);

				}

				function Detail(i) {
					var row = manager.getRow(i);
					parent.f_addTab(-1, '订单详情', "vstore/tb_sale_store/Detail.html?Fcode=" + row.Head.Fcode);
				}

				function ReturnDetail(i) {
					var row = manager.getRow(i);
					parent.f_addTab(-1, '退货详情', "vstore/tb_sale_store/ReturnDetail.html?Fcode=" + row.Head.Fcode);
				}

				function doSearch() { 
					var url = saleUrl +
						"&Fstatus=" + $("#Fstatus").val() +
						"&Fkey=" + $("#Fkey").val() +
						"&Fsdt=" + $("#sdt").val() +
						"&Fedt=" + $("#edt").val();

					manager.GetDataByURL(url);
				}
		</script>

	</head>
	<style>
		.dt {
			width: 60px;
		}
		
		.dd {
			margin-left: 70px;
		}
	</style>

	<body class="mainbody">
		<form id="form1" onsubmit="return false">
			<div>
				<div class="toolbar">
					<div class="div-content">
						<dl>
							<dt style="width: 60px;">时间区间</dt>
							<dd style="margin-left: 70px;">
								<div style="float:left"> <input type="text" id="sdt" name="sdt" ltype="date" ligerui="{width:120}" />
								</div>
								<div style="float:left;margin: 0 10px;"> 至 </div>
								<div style="float:left">
									<input type="text" id="edt" name="edt" ltype="date" ligerui="{width:120}" /></div>

							</dd>
							<dt style="width: 60px;">订单状态</dt>
							<dd style="margin-left: 70px;">
								<div style="margin-left: 10px;float:left;">
									<select name="Fstatus" id="Fstatus" ltype="select" ligerui="{width:120}">
										<option value="0" selected="selected">全部</option>
										<option value="2">待发货</option>
										<option value="3">部分发货</option>
										<option value="4">已发货</option>
										<option value="6">已完成</option>
									</select>
								</div>
							</dd>
							<dt style="width: 60px;">关键词</dt>
							<dd style="margin-left: 70px;">
								<div style="float:left;margin-left: 10px;"> <input type="text" placeholder="订单号" id="Fkey" name="Fkey" ltype="text" ligerui="{width:180}" />
								</div>
								<div style="float:left;margin-left: 10px;">
									<input style="display:inline" type="button" value="搜索" class="btn" onclick="doSearch();" />
								</div>
							</dd>
						</dl>
					</div>
				</div>
			</div>

			<div id="maingrid" style="background:#fff;"></div>

		</form>

	</body>

</html>